package string.test;

import java.security.InvalidParameterException;

import javax.naming.directory.InvalidAttributesException;

import org.apache.tomcat.util.http.fileupload.InvalidFileNameException;

public class StringPattern {
	static String regex = "[%0-9a-zA-Z._\\- ]*";
	public static void main(String[] args) {
		String test = "12-/r-asd.doc";
		
		//System.out.println(test.matches(regex));
		//System.out.println(parsePath(test));
		//System.out.println("asdf asd");
		validateNumber("321Asa2zZ09");
	}

	static String parsePath(String test) {
		if (test.matches(regex)) {
			if (test.contains("\\r") || test.contains("\\n")) {
				throw new InvalidFileNameException(test, "不合法的文件名！");
			} else {
				return test;
			}
		}
		throw new InvalidFileNameException(test, "不合法的文件名！");
	}
	
	static void validateNumber(String num){
		if(num != null){
			final int length = num.length();
			for(int i=0;i<length;i++){
				int c = num.charAt(i);
				if(c < 48 || (c > 57 && c < 65) || (c > 90 && c < 97 ) || c > 122){
					throw new InvalidParameterException("不合法的邮件参数!");
				}
			}
		}else{
			throw new NullPointerException();
		}
	}
}
